# 1.构建Get很单纯简单, 直接在url后面连上请求参数就行了

from urllib.request import Request
import urllib.request as ur
import urllib.parse as upa


url_baidusearch = 'http://www.baidu.com/s'
arg_kv = {'wd':'女神异闻录'}
get_kv_str = upa.urlencode(arg_kv)              # urlencode不仅可以转为url编码, 还能将dict转为"key=value"的请求格式
url_baidusearch_Get = url_baidusearch + '?' + get_kv_str
ua_header = {'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;'} # 模拟IE9
myreq = Request(url_baidusearch_Get, headers=ua_header)

response = ur.urlopen(myreq)
html = response.read().decode('utf8')
print(html)


